<template>
  <div class="icons">
    <swiper :options="swiperOption" v-if="pages.length">
      <swiper-slide v-for="(page,index) in pages" :key="index">
        <div class="icon-wrap" v-for="item in page" :key="item.id">
          <img :src="item.imgUrl" class="icon-img"/>
          <p class="icon-desc">{{item.desc}}</p>
        </div>
      </swiper-slide>
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    iconList: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        loop: true
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/variables.styl'
@import '~styles/mixins.styl'
.icons >>> .swiper-container
  padding-top .4rem
  width 100%
  height 8.7rem
  .icon-wrap
    float left
    width 25%
    height 3.67rem
    text-align center
    .icon-img
      height 2.32rem
    .icon-desc
      font-size .6rem
      line-height 1.2rem
      color $darkTextColor
      height 1.2rem
      ellipsis()
</style>
